using System;
using System.Collections.Generic;
using System.Text;
using Rapier.Kodachi.Shared;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.Serialization;

namespace Rapier.Kodachi.Core.Actions
{
    public class Run : Action
    {
        #region Constructor
        public Run(Plugin plugin)
            : base(plugin, "Rapier.CorePlugin.Run", "Run Command", "Runs the item text as a command.")
        {
            string itemPath = System.Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\cmd.exe";
            //CoreCatalog.CreateImageFromPath(this, itemPath);
            GetImage = delegate() { return CoreCatalog.GetImageFromPath(itemPath); };
        }
        #endregion

        #region Action Members
        public override bool IsValidDirect(Item directItem)
        {
            return directItem.Properties.ContainsKey("Text");
        }

        public override void Execute(Item[] directItems, Item[] indirectItems)
        {
            foreach (Item directItem in directItems)
            {
                ProcessStartInfo psi = new ProcessStartInfo("cmd", "/k \"" + directItem.Properties["Text"] + "\"");
                psi.CreateNoWindow = false;
                psi.WindowStyle = ProcessWindowStyle.Normal;
                psi.UseShellExecute = false;
                Process.Start(psi);
            }
        }
        #endregion
    }
}
